package com.loongnoy.controller;


import com.loongnoy.client.PointServiceClient;
import com.loongnoy.entity.Point;
import com.loongnoy.entity.RegisterUser;
import com.loongnoy.entity.ResultMsg;
import com.loongnoy.entity.User;
import com.loongnoy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private PointServiceClient pointService;

    @PostMapping("/registe")
    public ResultMsg registe(@RequestBody RegisterUser user) {
        // 保存用户信息
        System.out.println("保存用户信息：" + user);
        System.out.println("========================");
        User result = userService.save(user);
        
        // 初始化用户积分账户
        Point point = new Point();
        point.setUserId(result.getId());
        point.setTotal(500);
        point.setValid(500);
        point.setInvalid(0);
        ResultMsg resultMsg = pointService.add(point);
        System.out.println("初始化用户积分账户：" + resultMsg);

        return new ResultMsg(1, "注册成功", resultMsg);
    }
} 